from webutils.layers.managers import RedisManager


class Ratelimit(RedisManager):
    key_prefix = 'rl'

    async def increase_or_init(self, key, expire_in):
        key = f'{self.key_prefix}:{key}'
        value = await self.execute('INCR', key)
        value = int(value)
        if int(value) == 1:
            await self.execute('EXPIRE', key, expire_in)
        return value
